
#ifndef __RECTANGLE_H__
#define __RECTANGLE_H__

#define INVALIDATTRIBUTE -1

template <typename T> class Rectangle
{
 public:

      Rectangle(T length, T width);
      T computeArea() const;
      T computePerimeter() const;
      void setLength(const T length);
      void setWidth(const T width);

 private:

      T length_m;
      T width_m;

      bool isValidLength() const;
      bool isValidwidth() const;
};

template <typename T> 
Rectangle<T>::Rectangle(T length, T width)
{
      length_m = length;
      width_m  = width;
}


template <typename T> T
Rectangle<T>::computeArea() const
{
     if (isValidLength() && isValidwidth())
         return length_m * width_m;
     else 
         return INVALIDATTRIBUTE;
}


template <typename T> T
Rectangle<T>::computePerimeter() const
{
     if (isValidLength() && isValidwidth())
         return 2.0 * (length_m + width_m);
     else 
         return INVALIDATTRIBUTE;
}


template <typename T> void
Rectangle<T>::setLength(const T length) 
{
   length_m = length;
}

template <typename T> void
Rectangle<T>::setWidth(const T width) 
{
   width_m = width;
}


template <typename T> bool
Rectangle<T>::isValidLength() const
{
         return (length_m > 0)? 1:0;
}

template <typename T> bool
Rectangle<T>::isValidwidth() const
{
         return (width_m > 0)?1:0;
}
#endif

